package com.hoyue.classroom.controller;

import com.hoyue.classroom.bean.Course;
import com.hoyue.classroom.bean.Homework;
import com.hoyue.classroom.service.HomeworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author Hoyue_network1
 * @version 1.0
 * Creat by 2019/8/21 11:40
 */
@Controller
@RequestMapping("/homework")
public class HomeworkController {

	private String prefix = "homework";

	@Autowired
	HomeworkService homeworkService;

	@GetMapping()
	public String homework(Model model, HttpSession session) {
		Course course = (Course) session.getAttribute("course");
		model.addAttribute("course",course);
		return prefix + "/homework";
	}

	@ResponseBody
	@RequestMapping("/list")
	public List<Homework> list() {
		for (Homework homework : homeworkService.list()) {
			System.out.println(homework.getStartTime().toString());
		}
		return homeworkService.list();
	}
}
